package com.idanchuang.count.core.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author Richard_yyf
 * @version 1.0 2021/5/27
 */
@Component
@Aspect
@Slf4j
public class LogAspect {

    @Around("within(com.idanchuang.count.service.impl..*) " +
            "&& !execution(* destroy*(..))")
    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {

        String methodName = joinPoint.getSignature().getName();

        log.info("method:[{}], input params: [{}]", methodName, joinPoint.getArgs());

        Object result = joinPoint.proceed();

        if (result != null) {
            log.info("method:[{}], output params: [{}]", methodName, result);
        }

        return result;
    }
}
